﻿/*
 * Copyright (c) 2025 HiEasyX
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/**
 * \file Scroller.cpp
 * \brief The example of the usage of scroller control
 */

#include <include/hex.h>
#include <include/impl/EasyX/hex_impl_easyx.h>

int main() {
	initgraph(640, 480);

	BeginBatchDraw();

	HX::HXInitForEasyX();
	HX::SetBuffer(GetWorkingImage());

	setbkcolor(RGB(180, 180, 180));

	HX::WindowProfile windowProfile;
	windowProfile.Size = { 600, 400 };

	HX::ScrollerProfile scrollerProfile;

	IMAGE image;
	loadimage(&image, "./assets/logo.png");

	while (true) {
		cleardevice();

		HX::HXBegin();

		ExMessage message{};
		while (peekmessage(&message)) {
			HX::PushMessage(HX::GetHXMessage(&message));
		}

		HX::Window(HXStr("滚动框控件示例"), windowProfile);
		scrollerProfile.Size = { windowProfile.Size.X - 20, windowProfile.Size.Y - 80 };
		scrollerProfile.ViewSpace = { 3000, 3000 };
		HX::BeginScroller(scrollerProfile);

		HX::Text(HXStr("在 BeginScroller 和 EndScroller 之间的控件会被当作子控件"));

		static HX::ScrollerProfile Profile;
		Profile.Size      = {300, 100};
		Profile.ViewSpace = {7000, 2000};
		HX::BeginScroller(Profile);
		static HX::ButtonProfile p[30][30];
		for (auto j = 0; j < 30; ++j) {
			HX::BeginSameLine();
			for (auto i = 0; i < 30; ++i) {
				HX::Button(HXStr("支持 Scroller 嵌套 Scroller！"), p[i][j]);
			}
			HX::EndSameLine();
		}
		HX::EndScroller(Profile);

		for (auto i = 0; i < 10; ++i) {
			HX::BeginSameLine();
			for (auto j = 0; j < 10; ++j) {
				HX::Image(&image);
			}
			HX::EndSameLine();
		}

		HX::EndScroller(scrollerProfile);

		HX::End();
		HX::Render();

		FlushBatchDraw();

		Sleep(1);
	}

	return 0;
}